This script is used to clean water level data from HOBO water level loggers (U20L-04) designed for surface water level measurements. Cleaning and QA/QC steps include:

  1. removing bad data
  2. adjusting data for shifts in logger position
  3. converting stage to water depth
  4. checking results against manual measurements.

Inputs are water level logger raw data (periodically downloaded .csvs) and a manual measurement spreadsheet specific to the site being reviewed

Setup Package and function import from .R script

Additional functions Functions that open and concatenate formatted data files

2022

Fool1

Quick raw plot of point data

Figure 1.2021.FC1.all: Raw data for all HOBO water level loggers in the Fool 1 transect - 2021.

Figure 1.2021.FC1.all: Raw data for all HOBO water level loggers in the Fool 1 transect - 2021.

Subset based on logger location within the transect

press_raw_list <- split(press_raw, press_raw$trans_loc)

# Write out single data frames
for (i in seq(press_raw_list))
  assign(paste0('press_raw_', press_raw_list[[i]]$trans_loc[i]), press_raw_list[[i]])

Atmospheric

Check timesteps

Check if collection interval is consistent in dataset. Then identify missing timesteps.

#check if collection interval is consistent in dataset. Function as written only handles one interval but can be modified if interval was changed. 

ts_interval<- press_raw_atms$datetime[2] - press_raw_atms$datetime[1]

##round datetime to nearest whole interval
press_raw_atms <- press_raw_atms%>%
  mutate(datetime = round_date(datetime, as.period(ts_interval)))

#create full timeseries 
full_ts <- tibble(datetime=seq.POSIXt(press_raw_atms$datetime[1], press_raw_atms$datetime[length(press_raw_atms$datetime)], by=ts_interval))
press_raw_atms <- full_join(full_ts,press_raw_atms, by='datetime')

#identify missing timesteps:
miss_ts <- filter(press_raw_atms, is.na(pressure_kPa)) %>%
  pull(datetime)
  • The number of missing timesteps is 0
Check temperature

Keep in mind that the the factory calibrated ranges are: 0° to 40°C (32° to 104°F)

Figure1.2021.FC1.atms: Air temperature data captured by the HOBO water level logger monitoring atmospheric pressure in Fool 1 - 2021.

Clean data
1) Plot raw data with flag if raw level changes by more than 0.02.

Figure2.2021.FC1.atms:: Raw stage data from Fool 1 2021 with ‘flags’ where average stage changes by more than 20% in a single timestep

2) Manually identify points to be removed or corrected using the flagged plot
bad_id_fc1_atms22 <-  c(0)

vert_correction_fc1_atms22<- data.frame(ID = c(0:1), offset=c(0))%>%
  mutate(cumOffset = cumsum(offset))
3) Vertical adjustments
#function to make vertical correction and interpolate between missing values 
press_adj<- AdjPress(df=press_raw_atms, maxgap=8)%>%
    mutate(watershed = watershed)%>%
    mutate(site = site)%>%
    filter(ID > 3) %>% # beginning of data
    mutate(level_flag = ifelse(pressure_kPa < -65, 'Below Logger',
    ifelse(pressure_kPa > 75, 'Over Logger', 'In Range')))

#stageAdj<- AdjStage(maxgap=30)
Plot adjusted stage

Figure3.2021.FC1.atms: Pressure data from Fool 1 atmospheric data. No adjustments to the raw data are needed

Export cleaned data
#stage_final <- stage_adj %>%
press_final <- press_adj %>%
      drop_na() %>%
      mutate(date = lubridate::date(datetime)) %>%
      mutate(time = format(datetime, format = "%H:%M")) %>%
        #dplyr::select(watershed, site, date, time, wtr_depth, level_flag) 
      dplyr::select(watershed, site, date, time, adj_press, level_flag) 
    
loc_site<- paste(watershed,site, sep='_') 

interfiles <- 'clean_data/stage_pressure'
file_path <- paste(getwd(), interfiles,year,watershed,site, sep='/')
#saveRDS(stage_final, file=paste0('data/cln/wtr_lvl_',loc_site,'.csv'))
write_csv(press_final, file=paste0(file_path, '/',site, 'atms_clean.csv'))

Stream

mrg_press_adj <- as.data.frame(press_adj[,c('datetime','adj_press')])
  
stage_stream <- merge(press_raw_stream, mrg_press_adj, by = 'datetime') %>%
  mutate(adj_h2opressure = pressure_kPa - adj_press) %>%
  mutate(hobo_wtr_depth_cm = ((100*(adj_h2opressure*7.0)/145)) + 1.6) # kPa range 0-145, range at 10,000ft 0 to 7m plus 1.6cm for logger sensor height
Check timesteps

Check if collection interval is consistent in dataset. Then identify missing timesteps.

  • The number of missing timesteps is 0
Check temperature

Keep in mind that the the factory calibrated ranges are: 0° to 40°C (32° to 104°F)

Figure1.2021.FC1.stream: Air temperature data captured by the HOBO water level logger monitoring stream pressure in Fool 1 - 2021.

Clean data
1) Plot raw data with flag if raw level changes by more than 0.02.

Figure2.2021.FC1.stream: Raw pressure data from Fool 1 stream 2021 with ‘flags’ where average pressure changes by more than 20% in a single timestep

Clean raw stage

Plot raw water depth data with flag if raw level changes by more than 2%.

Figure2.2021.FC1.stream: Raw stage data from Fool 1 stream 2021 with ‘flags’ where average stage changes by more than 20% in a single timestep

2) Manually identify points to be removed or corrected using the flagged plot
bad_id_fc1_stream22 <-  c(0)

vert_correction_fc1_stream22<- data.frame(ID = c(0:1), offset=c(0))%>%
  mutate(cumOffset = cumsum(offset))
3) Vertical adjustments
#function to make vertical correction and interpolate between missing values 
stage_adj<- AdjStage(df=stage_stream, maxgap=8) %>%
    mutate(watershed = watershed) %>%
    mutate(site = site) %>%
    filter(ID > 3) %>% # beginning of data
    mutate(level_flag = ifelse(pressure_kPa < 0, 'Below Logger',
    ifelse(pressure_kPa > 145, 'Over Logger', 'In Range')))

#stageAdj<- AdjStage(maxgap=30)
Plot adjusted stage

Figure3.2021.FC1.stream: Pressure data from Fool 1 stream after the first round of adjustments, which include eliminating points where HOBO was out of the stream for periodic downloading and eliminating points collected after HOBO was removed from the stream. Both raw and adjusted values are shown

Plot adjusted values only:

Figure 3.1.5: Same as 3.1.4 but limited to adjusted values only.

4) Check manual measurements

Add and plot stream measurements performed from caprod post

# load manual measurements
interfiles <- 'formatted_data/manual_measurements/2022/caprod_measurements.csv'
file_path <- paste(getwd(),interfiles, sep='/')

manMeas <- read.table(file_path, skip=0, header=TRUE, sep=",", row.names = NULL, as.is = TRUE)

manMeas<- read.csv(file_path) %>%
      #timezone set to MST, change if loggers used MDT/MST
      mutate(datetime = round_date(mdy_hm(datetime, tz='America/Phoenix'),'30 minutes')) %>% 
      mutate(water_depth = to_bed_cm - to_water_surface_cm) %>%
      filter(., site == 'fc1')

cols <- c('watershed', 'site')
manMeas[cols] <- lapply(manMeas[cols], factor) 
#choose a static depth to bed value. Here we are using a mean of manual bed measurements from the top of the caprod post
stat_to_bed <- manMeas%>%
  summarize(mean_dep_to_bed = mean(to_bed_cm,na.rm=T))%>%
  pull(mean_dep_to_bed)

manMeas_fil <- manMeas %>%
      dplyr::rename(., wtr_depth_not_static = water_depth) %>%
      mutate(man_wtr_dep_static = stat_to_bed - to_water_surface_cm)
### 10 to convert mm to cm

depth_offset <- manMeas_fil %>%
  slice_max(datetime) %>%
  left_join(stage_adj %>%
              dplyr::select(datetime, adj_stage)) %>%
  mutate(depth_offset = man_wtr_dep_static - adj_stage)%>%
  pull(depth_offset)

Manual adjustments:

#start with 0 value, change if plots below suggest need for manual adjustment change value. 
manual_offset <- 0

stage_adj <- stage_adj%>%
  mutate(wtr_depth = adj_stage + depth_offset + manual_offset)

Compare cleaned water level to manual measurements

#plot difference between measured water depth and manual depth measurement
stage_adj <- as.data.frame(stage_adj)
stageAdj.man<- dplyr::left_join(manMeas_fil, stage_adj, by = 'datetime') %>%
      mutate(diff = man_wtr_dep_static-wtr_depth)

ggplot(stageAdj.man, aes(datetime, diff))+
  geom_point(size=3)+
  theme_minimal()

Plot adjusted stage
#plot water level time series with manual measurements as points
stage_check_plot<- stage_adj%>%
  dplyr::left_join(.,manMeas_fil, by = 'datetime') %>%
  ggplot(aes(datetime,wtr_depth))+
    geom_line()+
    geom_point(aes(datetime, man_wtr_dep_static),size=3,col='red')

ggplotly(stage_check_plot)

Figure 2.1.7: Adjusted stage data with manual measurements (points)

Export cleaned data
stage_final <- stage_adj %>%
      drop_na() %>%
      mutate(date = lubridate::date(datetime)) %>%
      mutate(time = format(datetime, format = "%H:%M")) %>%
      dplyr::select(watershed, site, date, time, wtr_depth, level_flag) 
    
loc_site<- paste(watershed,site, sep='_') 

interfiles <- 'clean_data/stage_pressure'
file_path <- paste(getwd(), interfiles,year,watershed,site, sep='/')
#saveRDS(stage_final, file=paste0('data/cln/wtr_lvl_',loc_site,'.csv'))
write_csv(stage_final, file=paste0(file_path, '/',site, '_clean.csv'))

LW1

mrg_press_adj <- as.data.frame(press_adj[,c('datetime','adj_press')])
  
stage_well <- merge(press_raw_lw1, mrg_press_adj, by = 'datetime') %>%
  mutate(adj_h2opressure = pressure_kPa - adj_press) %>%
  mutate(hobo_wtr_depth_cm = ((100*(adj_h2opressure*7.0)/145)) + 1.6) # kPa range 0-145, range at 10,000ft 0 to 7m plus 1.6cm for logger sensor height
Check timesteps

Check if collection interval is consistent in dataset. Then identify missing timesteps.

  • The number of missing timesteps is 0
Check temperature

Keep in mind that the the factory calibrated ranges are: 0° to 40°C (32° to 104°F)

Figure1.2202.FC1.lw1: Air temperature data captured by the HOBO water level logger monitoring stream pressure in Fool 1 - 2021.

Clean data
1) Plot raw pressure data with flag if raw level changes by more than 20%.

Figure2.2202.FC1.lw1: Raw pressure data from Fool 1 stream 2021 with ‘flags’ where average pressure changes by more than 20% in a single timestep

Plot raw water depth data with flag if raw level changes by more than 2%.

Figure2.2202.FC1.lw1: Raw stage data from Fool 1 stream 2021 with ‘flags’ where average stage changes by more than 20% in a single timestep

2) Manually identify points to be removed or corrected using the flagged plot
bad_id_fc1_well22 <-  c(55442:55497, 64917:64962, 69922:69942, 80107:80137, 85607:85642, 90672:90757, 90797:90822, 90522:90543, 95017:95061 )

vert_correction_fc1_well22<- data.frame(ID = c(0:1), offset=c(0))%>%
  mutate(cumOffset = cumsum(offset))
3) Vertical adjustments
#function to make vertical correction and interpolate between missing values 
stage_adj<- AdjStage(df=stage_well, maxgap=8) %>%
    mutate(watershed = watershed) %>%
    mutate(site = site) %>%
    filter(ID > 3) %>% # beginning of data
    mutate(level_flag = ifelse(pressure_kPa < 0, 'Below Logger',
    ifelse(pressure_kPa > 145, 'Over Logger', 'In Range')))

#stageAdj<- AdjStage(maxgap=30)

Plot adjusted stage

Figure3.2202.FC1.lw1: Pressure data from Fool 1 stream after the first round of adjustments, which include eliminating points where HOBO was out of the stream for periodic downloading and eliminating points collected after HOBO was removed from the stream. Both raw and adjusted values are shown

Plot adjusted values only:

Figure 3.1.5: Same as 3.1.4 but limited to adjusted values only.

4) Check manual measurements

Stream measurements performed from caprod post

# load manual measurements
interfiles <- 'formatted_data/manual_measurements/2022/manual_wells_waterlevel_meas.csv'
file_path <- paste(getwd(),interfiles, sep='/')

manMeas <- read.table(file_path, skip=0, header=TRUE, sep=",", row.names = NULL, as.is = TRUE)

manMeas<- read.csv(file_path) %>%
      #timezone set to MST, change if loggers used MDT/MST
  mutate(datetime = round_date(mdy_hm(datetime, tz='America/Phoenix'),'30 minutes')) %>% 
  mutate(water_depth = dep_to_bed-dep_to_water) %>% 
  filter(., site == 'fc1' & position == 'lw1' )
  
cols <- c('watershed', 'site', 'position', 'tech')
manMeas[cols] <- lapply(manMeas[cols], factor) 
#choose a static depth to bed value. Here we are using a mean of manual bed measurements from the top of the caprod post
stat_to_bed <- manMeas%>%
  summarize(mean_dep_to_bed = mean(dep_to_bed,na.rm=T))%>%
  pull(mean_dep_to_bed)

manMeas_fil <- manMeas %>%
      dplyr::rename(., wtr_depth_not_static = water_depth) %>%
      mutate(man_wtr_dep_static = stat_to_bed - dep_to_water)
### 10 to convert mm to cm

depth_offset <- manMeas_fil %>%
  slice_min(datetime) %>%
  left_join(stage_adj %>%
              dplyr::select(datetime, adj_stage)) %>%
  mutate(depth_offset = man_wtr_dep_static - adj_stage)%>%
  pull(depth_offset)

Manual adjustments:

#start with 0 value, change if plots below suggest need for manual adjustment change value. 
manual_offset <- 0

stage_adj <- stage_adj%>%
  mutate(wtr_depth = adj_stage + depth_offset + manual_offset)

Compare cleaned water level to manual measurements

#plot difference between measured water depth and manual depth measurement
stage_adj <- as.data.frame(stage_adj)
stageAdj.man<- dplyr::left_join(manMeas_fil, stage_adj, by = 'datetime') %>%
      mutate(diff = man_wtr_dep_static-wtr_depth)

ggplot(stageAdj.man, aes(datetime, diff))+
  geom_point(size=3)+
  theme_minimal()

Plot adjusted stage
#plot water level time series with manual measurements as points
stage_check_plot<- stage_adj%>%
  dplyr::left_join(.,manMeas_fil, by = 'datetime') %>%
  ggplot(aes(datetime,wtr_depth))+
    geom_line()+
    geom_point(aes(datetime, man_wtr_dep_static),size=3,col='red')

ggplotly(stage_check_plot)

Figure 2.1.7: Adjusted stage data with manual measurements (points)

Export cleaned data
stage_final <- stage_adj %>%
      drop_na() %>%
      mutate(date = lubridate::date(datetime)) %>%
      mutate(time = format(datetime, format = "%H:%M")) %>%
      dplyr::select(watershed, site, date, time, wtr_depth, level_flag) 
    
loc_site<- paste(watershed,site, sep='_') 

interfiles <- 'clean_data/stage_pressure'
file_path <- paste(getwd(), interfiles,year,watershed,site, sep='/')
#saveRDS(stage_final, file=paste0('data/cln/wtr_lvl_',loc_site,'.csv'))
write_csv(stage_final, file=paste0(file_path, '/',site, '_clean.csv'))

LW2

mrg_press_adj <- as.data.frame(press_adj[,c('datetime','adj_press')])
  
stage_well <- merge(press_raw_lw2, mrg_press_adj, by = 'datetime') %>%
  mutate(adj_h2opressure = pressure_kPa - adj_press) %>%
  mutate(hobo_wtr_depth_cm = ((100*(adj_h2opressure*7.0)/145)) + 1.6) # kPa range 0-145, range at 10,000ft 0 to 7m plus 1.6cm for logger sensor height
Check timesteps

Check if collection interval is consistent in dataset. Then identify missing timesteps.

  • The number of missing timesteps is 0
Check temperature

Keep in mind that the the factory calibrated ranges are: 0° to 40°C (32° to 104°F)

Figure1.2202.FC1.lw2: Air temperature data captured by the HOBO water level logger monitoring stream pressure in Fool 1 - 2021.

  1. Plot raw pressure data with flag if raw level changes by more than 2%.

Figure2.2202.FC1.lw2: Raw pressure data from Fool 1 stream 2021 with ‘flags’ where average pressure changes by more than 20% in a single timestep

Clean data
1) Plot raw water depth data with flag if raw level changes by more than 2%.

Figure2.2202.FC1.lw2: Raw stage data from Fool 1 stream 2021 with ‘flags’ where average stage changes by more than 20% in a single timestep

2) Manually identify points to be removed or corrected using the flagged plot
bad_id_fc1_well22 <-  c(64923:64968, 69923:69993, 80098:80148, 85603:85728, 90678:90798, 90798:90813, 90843:90928, 95013:95164 )

vert_correction_fc1_well22<- data.frame(ID = c(0:1), offset=c(0))%>%
  mutate(cumOffset = cumsum(offset))
3) Vertical adjustments
#function to make vertical correction and interpolate between missing values 
stage_adj<- AdjStage(df=stage_well, maxgap=8) %>%
    mutate(watershed = watershed) %>%
    mutate(site = site) %>%
    filter(ID > 3) %>% # beginning of data
    mutate(level_flag = ifelse(pressure_kPa < 0, 'Below Logger',
    ifelse(pressure_kPa > 145, 'Over Logger', 'In Range')))

#stageAdj<- AdjStage(maxgap=30)
Plot adjusted stage

Figure3.2202.FC1.lw2: Pressure data from Fool 1 stream after the first round of adjustments, which include eliminating points where HOBO was out of the stream for periodic downloading and eliminating points collected after HOBO was removed from the stream. Both raw and adjusted values are shown

Plot adjusted values only:

Figure 3.1.5: Same as 3.1.4 but limited to adjusted values only.

4) Check manual measurements

stream measurements performed from caprod post

# load manual measurements
interfiles <- 'formatted_data/manual_measurements/2022/manual_wells_waterlevel_meas.csv'
file_path <- paste(getwd(),interfiles, sep='/')

manMeas <- read.table(file_path, skip=0, header=TRUE, sep=",", row.names = NULL, as.is = TRUE)

manMeas<- read.csv(file_path) %>%
      #timezone set to MST, change if loggers used MDT/MST
  mutate(datetime = round_date(mdy_hm(datetime, tz='America/Phoenix'),'30 minutes')) %>% 
  mutate(water_depth = dep_to_bed-dep_to_water) %>% 
  filter(., site == 'fc1' & position == 'lw2' )
  
cols <- c('watershed', 'site', 'position', 'tech')
manMeas[cols] <- lapply(manMeas[cols], factor) 
#choose a static depth to bed value. Here we are using a mean of manual bed measurements from the top of the caprod post
stat_to_bed <- manMeas%>%
  summarize(mean_dep_to_bed = mean(dep_to_bed,na.rm=T))%>%
  pull(mean_dep_to_bed)

manMeas_fil <- manMeas %>%
      dplyr::rename(., wtr_depth_not_static = water_depth) %>%
      mutate(man_wtr_dep_static = stat_to_bed - dep_to_water)
### 10 to convert mm to cm

depth_offset <- manMeas_fil %>%
  slice_min(datetime) %>%
  left_join(stage_adj %>%
              dplyr::select(datetime, adj_stage)) %>%
  mutate(depth_offset = man_wtr_dep_static - adj_stage)%>%
  pull(depth_offset)

Manual adjustments:

#start with 0 value, change if plots below suggest need for manual adjustment change value. 
manual_offset <- 0

stage_adj <- stage_adj%>%
  mutate(wtr_depth = adj_stage + depth_offset + manual_offset)
Compare cleaned water level to manual measurements
#plot difference between measured water depth and manual depth measurement
stage_adj <- as.data.frame(stage_adj)
stageAdj.man<- dplyr::left_join(manMeas_fil, stage_adj, by = 'datetime') %>%
      mutate(diff = man_wtr_dep_static-wtr_depth)

ggplot(stageAdj.man, aes(datetime, diff))+
  geom_point(size=3)+
  theme_minimal()

Plot adjusted stage
#plot water level time series with manual measurements as points
stage_check_plot<- stage_adj%>%
  dplyr::left_join(.,manMeas_fil, by = 'datetime') %>%
  ggplot(aes(datetime,wtr_depth))+
    geom_line()+
    geom_point(aes(datetime, man_wtr_dep_static),size=3,col='red')

ggplotly(stage_check_plot)

Figure 2.1.7: Adjusted stage data with manual measurements (points)

Export cleaned data
stage_final <- stage_adj %>%
      drop_na() %>%
      mutate(date = lubridate::date(datetime)) %>%
      mutate(time = format(datetime, format = "%H:%M")) %>%
      dplyr::select(watershed, site, date, time, wtr_depth, level_flag) 
    
loc_site<- paste(watershed,site, sep='_') 

interfiles <- 'clean_data/stage_pressure'
file_path <- paste(getwd(), interfiles,year,watershed,site, sep='/')
#saveRDS(stage_final, file=paste0('data/cln/wtr_lvl_',loc_site,'.csv'))
write_csv(stage_final, file=paste0(file_path, '/',site, '_clean.csv'))
# Simple df of adjusted values for stacked plot (see below)
simplefc1lw2_22 <- stage_adj %>%
  select(datetime, wtr_depth, site) %>%
  drop_na()

RW1

mrg_press_adj <- as.data.frame(press_adj[,c('datetime','adj_press')])
  
stage_well <- merge(press_raw_rw1, mrg_press_adj, by = 'datetime') %>%
  mutate(adj_h2opressure = pressure_kPa - adj_press) %>%
  mutate(hobo_wtr_depth_cm = ((100*(adj_h2opressure*7.0)/145)) + 1.6) # kPa range 0-145, range at 10,000ft 0 to 7m plus 1.6cm for logger sensor height
Create complete timeseries to identify any missing datetimes from the dataframe
  • The number of missing timesteps is 0
Plot Raw Pressure
  1. Plot temperature for quick checks

Figure1.2202.FC1.rw1: Air temperature data captured by the HOBO water level logger monitoring stream pressure in Fool 1 - 2021.

  1. Plot raw pressure data with flag if raw level changes by more than 2%.

Figure2.2202.FC1.rw1: Raw pressure data from Fool 1 stream 2021 with ‘flags’ where average pressure changes by more than 20% in a single timestep

Clean raw stage
  1. Plot raw water depth data with flag if raw level changes by more than 2%.

Figure2.2202.FC1.rw1: Raw stage data from Fool 1 stream 2021 with ‘flags’ where average stage changes by more than 20% in a single timestep

  1. Manually identify points to be removed or corrected using the flagged plot
bad_id_fc1_well22 <-  c(46979:49719, 55439:55479, 64919:64954, 69914:69949, 80104:80159, 85604:85619, 90689:90729, 90799:90834, 95014:95063)

vert_correction_fc1_well22<- data.frame(ID = c(0:1), offset=c(0))%>%
  mutate(cumOffset = cumsum(offset))
  1. Vertical adjustments
#function to make vertical correction and interpolate between missing values 
stage_adj<- AdjStage(df=stage_well, maxgap=8) %>%
    mutate(watershed = watershed) %>%
    mutate(site = site) %>%
    filter(ID > 3) %>% # beginning of data
    mutate(level_flag = ifelse(pressure_kPa < 0, 'Below Logger',
    ifelse(pressure_kPa > 145, 'Over Logger', 'In Range')))

#stageAdj<- AdjStage(maxgap=30)
Plot adjusted stage

Figure3.2202.FC1.rw1: Pressure data from Fool 1 stream after the first round of adjustments, which include eliminating points where HOBO was out of the stream for periodic downloading and eliminating points collected after HOBO was removed from the stream. Both raw and adjusted values are shown

Plot adjusted values only:

Figure 3.1.5: Same as 3.1.4 but limited to adjusted values only.

  1. Check manual measurements - stream measurements performed from caprod post
# load manual measurements
interfiles <- 'formatted_data/manual_measurements/2022/manual_wells_waterlevel_meas.csv'
file_path <- paste(getwd(),interfiles, sep='/')

manMeas <- read.table(file_path, skip=0, header=TRUE, sep=",", row.names = NULL, as.is = TRUE)

manMeas<- read.csv(file_path) %>%
      #timezone set to MST, change if loggers used MDT/MST
  mutate(datetime = round_date(mdy_hm(datetime, tz='America/Phoenix'),'30 minutes')) %>% 
  mutate(water_depth = dep_to_bed-dep_to_water) %>% 
  filter(., site == 'fc1' & position == 'rw1' )
  
cols <- c('watershed', 'site', 'position', 'tech')
manMeas[cols] <- lapply(manMeas[cols], factor) 
#choose a static depth to bed value. Here we are using a mean of manual bed measurements from the top of the caprod post
stat_to_bed <- manMeas%>%
  summarize(mean_dep_to_bed = mean(dep_to_bed,na.rm=T))%>%
  pull(mean_dep_to_bed)

manMeas_fil <- manMeas %>%
      dplyr::rename(., wtr_depth_not_static = water_depth) %>%
      mutate(man_wtr_dep_static = stat_to_bed - dep_to_water)
### 10 to convert mm to cm

depth_offset <- manMeas_fil %>%
  slice_min(datetime) %>%
  left_join(stage_adj %>%
              dplyr::select(datetime, adj_stage)) %>%
  mutate(depth_offset = man_wtr_dep_static - adj_stage)%>%
  pull(depth_offset)

Manual adjustments:

#start with 0 value, change if plots below suggest need for manual adjustment change value. 
manual_offset <- 0

stage_adj <- stage_adj%>%
  mutate(wtr_depth = adj_stage + depth_offset + manual_offset)
Compare cleaned water level to manual measurements
#plot difference between measured water depth and manual depth measurement
stage_adj <- as.data.frame(stage_adj)
stageAdj.man<- dplyr::left_join(manMeas_fil, stage_adj, by = 'datetime') %>%
      mutate(diff = man_wtr_dep_static-wtr_depth)

ggplot(stageAdj.man, aes(datetime, diff))+
  geom_point(size=3)+
  theme_minimal()

#plot water level time series with manual measurements as points
stage_check_plot<- stage_adj%>%
  dplyr::left_join(.,manMeas_fil, by = 'datetime') %>%
  ggplot(aes(datetime,wtr_depth))+
    geom_line()+
    geom_point(aes(datetime, man_wtr_dep_static),size=3,col='red')

ggplotly(stage_check_plot)

Figure 2.1.7: Adjusted stage data with manual measurements (points)

Export cleaned data
stage_final <- stage_adj %>%
      drop_na() %>%
      mutate(date = lubridate::date(datetime)) %>%
      mutate(time = format(datetime, format = "%H:%M")) %>%
      dplyr::select(watershed, site, date, time, wtr_depth, level_flag) 
    
loc_site<- paste(watershed,site, sep='_') 

interfiles <- 'clean_data/stage_pressure'
file_path <- paste(getwd(), interfiles,year,watershed,site, sep='/')
#saveRDS(stage_final, file=paste0('data/cln/wtr_lvl_',loc_site,'.csv'))
write_csv(stage_final, file=paste0(file_path, '/',site, '_clean.csv'))
# Simple df of adjusted values for stacked plot (see below)
simplefc1rw1_22 <- stage_adj %>%
  select(datetime, wtr_depth, site) %>%
  drop_na()

RW2

#some text here

Fool2

#some text here

Atmospheric

#some text here

Stream

#some text here

LW1

#some text here

LW2

#some text here

RW1

#some text here

RW2

#some text here

2021

Fool1

Quick raw plot of point data

Figure 1.2021.FC1.all: Raw data for all HOBO water level loggers in the Fool 1 transect - 2021.

Figure 1.2021.FC1.all: Raw data for all HOBO water level loggers in the Fool 1 transect - 2021.

Subset based on logger location within the transect

press_raw_list <- split(press_raw, press_raw$trans_loc)

# Write out single data frames
for (i in seq(press_raw_list))
  assign(paste0('press_raw_', press_raw_list[[i]]$trans_loc[i]), press_raw_list[[i]])

Atmospheric

#some text here

Stream

#some text here

LW1

#some text here

LW2

#some text here

RW1

#some text here

RW2

#some text here

Fool2

#some text here

Atmospheric

#some text here

Stream

#some text here

LW1

#some text here

LW2

#some text here

RW1

#some text here

RW2

#some text here